
package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.ST;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class NullFlavorImpl extends CSImpl implements CS
 {
     public static final String RCS_ID
         = "$Header: NullFlavorImpl.java 115.13 2005/05/26 23:29:18 mmoores noship $";
     public static final CS NI = valueOf("NI");
     public static final CS NA = valueOf("NA");
     public static final CS UNK = valueOf("UNK");
     public static final CS ASKU = valueOf("ASKU");
     public static final CS NAV = valueOf("NAV");
     public static final CS OTH = valueOf("OTH");
     public static final CS PINF = valueOf("PINF");
     public static final CS NINF = valueOf("NINF");
     public static final CS MSK = valueOf("MSK");
     public static final CS NP = valueOf("NP");
     private static final NullFlavorTree _hierarchy = new NullFlavorTree();
     
     private static class NullFlavorTree
     {
         private NullFlavorTreeNode _head
             = new NullFlavorTreeNode(null, NullFlavorImpl.NI);
         
         public NullFlavorTree() {
             NullFlavorTreeNode nullflavortreenode
                 = new NullFlavorTreeNode(NullFlavorImpl.NA);
             NullFlavorTreeNode nullflavortreenode_0_
                 = new NullFlavorTreeNode(NullFlavorImpl.UNK);
             NullFlavorTreeNode nullflavortreenode_1_
                 = new NullFlavorTreeNode(NullFlavorImpl.OTH);
             NullFlavorTreeNode nullflavortreenode_2_
                 = new NullFlavorTreeNode(NullFlavorImpl.ASKU);
             NullFlavorTreeNode nullflavortreenode_3_
                 = new NullFlavorTreeNode(NullFlavorImpl.NAV);
             NullFlavorTreeNode nullflavortreenode_4_
                 = new NullFlavorTreeNode(NullFlavorImpl.PINF);
             NullFlavorTreeNode nullflavortreenode_5_
                 = new NullFlavorTreeNode(NullFlavorImpl.NINF);
             _head.add(nullflavortreenode);
             _head.add(nullflavortreenode_0_);
             _head.add(nullflavortreenode_1_);
             nullflavortreenode_0_.add(nullflavortreenode_2_);
             nullflavortreenode_2_.add(nullflavortreenode_3_);
             nullflavortreenode_1_.add(nullflavortreenode_4_);
             nullflavortreenode_1_.add(nullflavortreenode_5_);
         }
         
         public boolean unknown(CS cs) {
             NullFlavorTreeNode nullflavortreenode = find(cs);
             if (nullflavortreenode != null)
                 return nullflavortreenode.inFamily(NullFlavorImpl.UNK);
             return false;
         }
         
         public boolean notApplicable(CS cs) {
             NullFlavorTreeNode nullflavortreenode = find(cs);
             if (nullflavortreenode != null)
                 return nullflavortreenode.inFamily(NullFlavorImpl.NA);
             return false;
         }
         
         public boolean other(CS cs) {
             NullFlavorTreeNode nullflavortreenode = find(cs);
             if (nullflavortreenode != null)
                 return nullflavortreenode.inFamily(NullFlavorImpl.OTH);
             return false;
         }
         
         public CS commonAncestor(CS cs, CS cs_6_) {
             return null;
         }
         
         private NullFlavorTreeNode find(CS cs) {
             return _head.find(cs);
         }
     }
     
     private static class NullFlavorTreeNode
     {
         public NullFlavorTreeNode parent;
         public CS nullFlavor;
         public List children;
         
         public NullFlavorTreeNode(NullFlavorTreeNode nullflavortreenode_7_,
                                   CS cs) {
             parent = nullflavortreenode_7_;
             nullFlavor = cs;
             children = new ArrayList();
         }
         
         public NullFlavorTreeNode(CS cs) {
             this(null, cs);
         }
         
         public void add(NullFlavorTreeNode nullflavortreenode_8_) {
             children.add(nullflavortreenode_8_);
             nullflavortreenode_8_.parent = this;
         }
         
         public NullFlavorTreeNode find(CS cs) {
             if (nullFlavor.equal(cs).isTrue())
                 return this;
             NullFlavorTreeNode nullflavortreenode_9_ = null;
             for (Iterator iterator = children.iterator();
                  nullflavortreenode_9_ == null && iterator.hasNext();
                  nullflavortreenode_9_
                      = ((NullFlavorTreeNode) iterator.next()).find(cs)) {
                 /* empty */
             }
             return nullflavortreenode_9_;
         }
         
         public boolean inFamily(CS cs) {
             boolean bool = false;
             if (nullFlavor.equal(cs).isTrue())
                 bool = true;
             else if (parent != null)
                 bool = parent.inFamily(cs);
             return bool;
         }
     }
     
     public static CS valueOf(String string) {
         ST st = STImpl.valueOf(string);
         return valueOf(st);
     }
     
     public static CS valueOf(ST st) {
         return new NullFlavorImpl(st);
     }
     
     protected NullFlavorImpl(ST st) {
         super(st);
     }
     
     public BL equal(ANY any) {
         if (!(any instanceof CS))
             return BLImpl.FALSE;
         if (this.isNull().or(any.isNull()).isTrue())
             return BLImpl.FALSE;
         CS cs = (CS) any;
         return this.code().equal(cs.code());
     }
     
     public static BL notApplicable(CS cs) {
         return BLImpl.valueOf(_hierarchy.notApplicable(cs));
     }
     
     public static BL unknown(CS cs) {
         return BLImpl.valueOf(_hierarchy.unknown(cs));
     }
     
     public static BL other(CS cs) {
         return BLImpl.valueOf(_hierarchy.other(cs));
     }
     
     public String toString() {
         if (this.code() == null)
             return "NullFlavor: null";
         return "NullFlavor: " + this.code().toString();
     }
 }
